/**
 *
 * Copyright 2012 TeleNav, Inc. All rights reserved.
 * Route.java
 *
 */
package com.telenav.snowsweeper.data;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;


/**
 *@author hhzhu
 *@date 2012-12-7
 */
public class Route
{
    List<Integer> tracer = new ArrayList<Integer>();
    
    public void addEdge(int index) {
    	tracer.add(index);
    }
    
    public String getStringHead() {
    	return "\"route\" : [";
    }
    
    public String getStringEnd() {
    	return "]"; 
    }
    
    public void appendIndex(Integer index, StringBuilder builder) {
    	builder.append("{\"id\": \"");
    	builder.append(index);
    	builder.append("\"}");
    }
    
    public String toString()
    {
        StringBuilder builder = new StringBuilder();
        builder.append(getStringHead());
        ListIterator<Integer> iterator = tracer.listIterator();
        if (iterator.hasNext())
        	appendIndex(iterator.next(), builder);
        while (iterator.hasNext()) {
        	builder.append(',');
        	appendIndex(iterator.next(), builder);
        }
        builder.append(getStringEnd());
        return builder.toString();
    }
    
    public String getRequestParamers()
    {
        StringBuilder builder = new StringBuilder();
        ListIterator<Integer> iterator = tracer.listIterator();
        if (iterator.hasNext())
        {
            builder.append(iterator.next());
        }
        while (iterator.hasNext()) {
            builder.append('|');
            builder.append(iterator.next());
        }
        return builder.toString();
    }
}
